import request from '@/utils/request';
import type { VepParameter, VepResult } from 'api/types/vep';
import {EcoData} from "api/vepApi";

const prefix_para = '/api/vep-parameters/vep_parameters';

export const addVepParameter = (data: VepParameter) =>
    request.post(prefix_para, data);

export const getVepParameters = () =>
    request.get<VepParameter[]>(prefix_para);

export const getVepParameter = (id: number) =>
    request.get<VepParameter>(`${prefix_para}/${id}`);

export const updateVepParameter = (id: number, data: Partial<VepParameter>) =>
    request.put(`${prefix_para}/${id}`, data);

export const deleteVepParameter = (id: number) =>
    request.delete(`${prefix_para}/${id}`);


const prefix_res = '/api/vep-results/vep_results';

export const addVepResult = (data: VepResult) =>
    request.post(prefix_res, data);

export const getVepResults = () =>
    request.get<VepResult[]>(prefix_res);

export const getVepResult = (id: number) =>
    request.get<VepResult>(`${prefix_res}/${id}`);

export const updateVepResult = (id: number, data: Partial<VepResult>) =>
    request.put(`${prefix_res}/${id}`, data);

export const deleteVepResult = (id: number) =>
    request.delete(`${prefix_res}/${id}`);


const prefix = '/api/vep-parameters/vep_parameters_by_fields'

/**
 * 根据年份、城市、区县、乡镇、名称查询 VEP 参数
 */
export const getVepParameterByPath = (year: number, city: string, district: string, town: string, name: string) =>
    request.get<VepParameter>(`${prefix}/${year}/${encodeURIComponent(city)}/${encodeURIComponent(district)}/${encodeURIComponent(town)}/${encodeURIComponent(name)}`)

/**
 * 根据年份、城市、区县、乡镇、名称新增 VEP 参数
 */
export const addVepParameterByPath = (year: number, city: string, district: string, town: string, name: string, data: Partial<VepParameter>) =>
    request.post<VepParameter>(`${prefix}/${year}/${encodeURIComponent(city)}/${encodeURIComponent(district)}/${encodeURIComponent(town)}/${encodeURIComponent(name)}`, data)

/**
 * 根据年份、城市、区县、乡镇、名称更新 VEP 参数
 */
export const updateVepParameterByPath = (year: number, city: string, district: string, town: string, name: string, data: Partial<VepParameter>) =>
    request.put<VepParameter>(`${prefix}/${year}/${encodeURIComponent(city)}/${encodeURIComponent(district)}/${encodeURIComponent(town)}/${encodeURIComponent(name)}`, data)

/**
 * 根据年份、城市、区县、乡镇、名称删除 VEP 参数
 */
export const deleteVepParameterByPath = (year: number, city: string, district: string, town: string, name: string) =>
    request.delete(`${prefix}/${year}/${encodeURIComponent(city)}/${encodeURIComponent(district)}/${encodeURIComponent(town)}/${encodeURIComponent(name)}`)


const prefix1 = '/api/vep-results/vep_results_by_fields'

/**
 * 根据年份、城市、区县、乡镇、名称获取 VEP 结果
 */
export const getVepResultByPath = (year: number, city: string, district: string, town: string, name: string) =>
    request.get<VepResult>(`${prefix1}/${year}/${encodeURIComponent(city)}/${encodeURIComponent(district)}/${encodeURIComponent(town)}/${encodeURIComponent(name)}`)

/**
 * 根据年份、城市、区县、乡镇、名称更新 VEP 结果
 */
export const updateVepResultByPath = (year: number, city: string, district: string, town: string, name: string, data: Partial<VepResult>) =>
    request.put<VepResult>(`${prefix1}/${year}/${encodeURIComponent(city)}/${encodeURIComponent(district)}/${encodeURIComponent(town)}/${encodeURIComponent(name)}`, data)

/**
 * 根据年份、城市、区县、乡镇、名称删除 VEP 结果
 */
export const deleteVepResultByPath = (year: number, city: string, district: string, town: string, name: string) =>
    request.delete(`${prefix1}/${year}/${encodeURIComponent(city)}/${encodeURIComponent(district)}/${encodeURIComponent(town)}/${encodeURIComponent(name)}`)


export const getVepPageData = () =>
    request.get<EcoData[]>('/api/homepage-data/vepPage', {
        params: {
            year: 2024,
            district: '铅山县'
        }
    });

// 获取VEP项目展示数据（包含面积信息）
export function getVepShowcaseData() {
    return request({
        // url: '/api/vep-results/showcase',
        url: '/api/vep-results/showcase-projects',
        method: 'get'
    })
}